import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '../layout'
Vue.use(Router)

const routes = [
  {
    path: '/login',
    component: () => import('../views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('../views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('../views/index/index'),
        meta: { title: '首页', icon: 'el-icon-s-home svg-icon' }
      }
    ]
  },
  {
    path: '/setting',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Setting',
        component: () => import('../views/setting/index'),
        meta: { title: '修改密码', icon: 'el-icon-setting svg-icon' }
      }
    ]
  },
  {
    path: '/studentManage',
    component: Layout,
    redirect: '/studentManage/studentManage',
    meta: { title: '学生管理', icon: 'el-icon-set-up svg-icon' },
    children: [
      {
        path: 'student',
        name: 'Student',
        component: () => import('../views/studentManage/student/index'),
        meta: { title: '学生', icon: 'el-icon-user-solid svg-icon' }
      },
      {
        path: 'grade',
        name: 'Grade',
        component: () => import('../views/studentManage/grade/index'),
        meta: { title: '班级', icon: 'el-icon-set-up svg-icon' }
      }
    ]
  },
  {
    path: '/teacherManage',
    component: Layout,
    redirect: '/studentManage/teacher',
    meta: { title: '教师管理', icon: 'el-icon-set-up svg-icon' },
    children: [
      {
        path: 'teacher',
        name: 'Teacher',
        component: () => import('../views/teachermanage/teacher/index'),
        meta: { title: '教师', icon: 'el-icon-user svg-icon' }
      },
      {
        path: 'department',
        name: 'Department',
        component: () => import('../views/teachermanage/department/index'),
        meta: { title: '部门', icon: 'el-icon-user svg-icon' }
      }
    ]
  },
  {
    path: '/majorManage',
    component: Layout,
    redirect: '/majorManage/major',
    meta: { title: '专业管理', icon: 'el-icon-set-up svg-icon' },
    children: [
      {
        path: 'major',
        name: 'Major',
        component: () => import('../views/majormanage/major/index'),
        meta: { title: '专业', icon: 'el-icon-user svg-icon' }
      },
      {
        path: 'academy',
        name: 'Academy',
        component: () => import('../views/majormanage/academy/index'),
        meta: { title: '学院', icon: 'el-icon-user svg-icon' }
      }
    ]
  },
  {
    path: '/attendanceManage',
    component: Layout,
    redirect: '/attendanceManage/attendance',
    meta: { title: '考勤管理', icon: 'el-icon-set-up svg-icon' },
    children: [
      {
        path: 'attendance',
        name: 'Attendance',
        component: () => import('../views/attendancemanage/attendance/index'),
        meta: { title: '考勤', icon: 'el-icon-user svg-icon' }
      },
      {
        path: 'way',
        name: 'way',
        component: () => import('../views/attendancemanage/way/index'),
        meta: { title: '考勤方式', icon: 'el-icon-user svg-icon' }
      }
    ]
  },
  {
    path: '/scoreManage',
    component: Layout,
    redirect: '/scoreManage/score',
    meta: { title: '成绩管理', icon: 'el-icon-set-up svg-icon' },
    children: [
      {
        path: 'score',
        name: 'Score',
        component: () => import('../views/scoremanage/score/index'),
        meta: { title: '成绩', icon: 'el-icon-user svg-icon' }
      },
      {
        path: 'scoreKind',
        name: 'ScoreKind',
        component: () => import('../views/scoremanage/scoreKind/index'),
        meta: { title: '成绩类型', icon: 'el-icon-user svg-icon' }
      }
    ]
  },
  {
    path: '/dormitoryManage',
    component: Layout,
    redirect: '/dormitoryManage/dormitory',
    meta: { title: '宿舍管理', icon: 'el-icon-set-up svg-icon' },
    children: [
      {
        path: 'dormitory',
        name: 'Dormitory',
        component: () => import('../views/dormitorymanage/dormitory/index'),
        meta: { title: '宿舍', icon: 'el-icon-user svg-icon' }
      },
      {
        path: 'apartment',
        name: 'Apartment',
        component: () => import('../views/dormitorymanage/apartment/index'),
        meta: { title: '公寓', icon: 'el-icon-user svg-icon' }
      }
    ]
  },
  {
    path: '/courseManage',
    component: Layout,
    redirect: '/courseManage/course',
    meta: { title: '课程管理', icon: 'el-icon-set-up svg-icon' },
    children: [
      {
        path: 'course',
        name: 'Course',
        component: () => import('../views/coursemanage/course/index'),
        meta: { title: '课程', icon: 'el-icon-user svg-icon' }
      },
      {
        path: 'courseKind',
        name: 'CourseKind',
        component: () => import('../views/coursemanage/courseKind/index'),
        meta: { title: '课程种类', icon: 'el-icon-user svg-icon' }
      }
    ]
  },
  {
    path: '/actionManage',
    component: Layout,
    redirect: '/actionManage/action',
    meta: { title: '二课管理', icon: 'el-icon-set-up svg-icon' },
    children: [
      {
        path: 'action',
        name: 'Action',
        component: () => import('../views/actionmanage/action/index'),
        meta: { title: '二课活动', icon: 'el-icon-user svg-icon' }
      },
      {
        path: 'actionKind',
        name: 'ActionKind',
        component: () => import('../views/actionmanage/actionKind/index'),
        meta: { title: '活动种类', icon: 'el-icon-user svg-icon' }
      }
    ]
  },
  {
    path: '/introduce',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Introduce',
        component: () => import('../views/introduce/index'),
        meta: { title: '系统介绍', icon: 'el-icon-info svg-icon' }
      }
    ]
  },
  {
    path: '/document',
    component: Layout,
    children: [
      {
        path: 'http://localhost:8000/swagger-ui.html',
        name: 'Document',
        meta: { title: '后台文档', icon: 'el-icon-s-help svg-icon' }
      }
    ]
  },
  {
    path: '/data',
    component: Layout,
    children: [
      {
        path: 'http://localhost:8000/druid',
        name: 'Data',
        meta: { title: '数据监控', icon: 'el-icon-coin svg-icon' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: routes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
